{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-08-19T13:49:52.073560Z",
     "start_time": "2025-08-19T13:49:50.694059Z"
    }
   },
   "source": [
    "import os\n",
    "from openai import OpenAI\n",
    "\n",
    "# 从环境变量获取 DeepSeek API Key\n",
    "# api_key = os.getenv(\"DEEPSEEK_API_KEY\")\n",
    "\n",
    "# 国内代理方式\n",
    "# client = OpenAI(\n",
    "#     api_key = \"sk-y7DHfp9fzuCxOVm2158638099f9541D3833aB4F4Ed674aCf\",\n",
    "#     base_url = \"https://vip.apiyi.com/v1\"    # 此处代理方式，如果是OpenAI官方接口需调整接口地址\n",
    "# )\n",
    "\n",
    "client = OpenAI(\n",
    "    api_key = \"sk-y7DHfp9fzuCxOVm2158638099f9541D3833aB4F4Ed674aCf\",\n",
    "    base_url = \"http://103.143.238.144:11434/v1\"    # 此处代理方式，如果是OpenAI官方接口需调整接口地址\n",
    ")"
   ],
   "outputs": [],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-19T13:49:57.747220Z",
     "start_time": "2025-08-19T13:49:57.743026Z"
    }
   },
   "cell_type": "code",
   "source": [
    "SYSTEM_PROMPT = \"\"\"\n",
    "你是一个资深的小红书爆款文案专家，擅长结合最新潮流和产品卖点，创作引人入胜、高互动、高转化的笔记文案。你的工作模式是严格的“思考-行动-观察”，你必须通过调用functions中的工具来收集必要的、经过筛选的产品及热点信息，禁止直接使用你的内部知识生成最终文案。\n",
    "\n",
    "你的任务是根据用户提供的产品和需求，调用工具收集信息，然后生成包含标题、正文、相关标签和表情符号的完整小红书笔记，禁止直接使用你的内部知识直接生成最终方案。\n",
    "\n",
    "请始终采用'Thought-Action-Observation'模式进行推理和行动。文案风格需活泼、真诚、富有感染力。当完成任务后，请以JSON格式直接输出最终文案，格式如下：\n",
    "```json\n",
    "{\n",
    "  \"title\": \"小红书标题\",\n",
    "  \"body\": \"小红书正文\",\n",
    "  \"hashtags\": [\"#标签1\", \"#标签2\", \"#标签3\", \"#标签4\", \"#标签5\"],\n",
    "  \"emojis\": [\"✨\", \"🔥\", \"💖\"]\n",
    "}\n",
    "```\n",
    "在生成文案前，请务必先思考并收集足够的信息，信息搜集可采用网络搜索、内部产品库查询，表情也可根据产品风格进行查询案例库。\n",
    "\"\"\""
   ],
   "id": "c08f503e53efc980",
   "outputs": [],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-19T13:49:59.361395Z",
     "start_time": "2025-08-19T13:49:59.355670Z"
    }
   },
   "cell_type": "code",
   "source": [
    "TOOLS_DEFINITION = [\n",
    "    {\n",
    "        \"type\": \"function\",\n",
    "        \"function\": {\n",
    "            \"name\": \"search_web\",\n",
    "            \"description\": \"搜索互联网上的实时信息，用于获取最新新闻、流行趋势、用户评价、行业报告等。请确保搜索关键词精确，避免宽泛的查询。\",\n",
    "            \"parameters\": {\n",
    "                \"type\": \"object\",\n",
    "                \"properties\": {\n",
    "                    \"query\": {\n",
    "                        \"type\": \"string\",\n",
    "                        \"description\": \"要搜索的关键词或问题，例如'最新小红书美妆趋势'或'深海蓝藻保湿面膜 用户评价'\"\n",
    "                    }\n",
    "                },\n",
    "                \"required\": [\"query\"]\n",
    "            }\n",
    "        }\n",
    "    },\n",
    "    {\n",
    "        \"type\": \"function\",\n",
    "        \"function\": {\n",
    "            \"name\": \"query_product_database\",\n",
    "            \"description\": \"查询内部产品数据库，获取指定产品的详细卖点、成分、适用人群、使用方法等信息。\",\n",
    "            \"parameters\": {\n",
    "                \"type\": \"object\",\n",
    "                \"properties\": {\n",
    "                    \"product_name\": {\n",
    "                        \"type\": \"string\",\n",
    "                        \"description\": \"要查询的产品名称，例如'深海蓝藻保湿面膜'\"\n",
    "                    }\n",
    "                },\n",
    "                \"required\": [\"product_name\"]\n",
    "            }\n",
    "        }\n",
    "    },\n",
    "    {\n",
    "        \"type\": \"function\",\n",
    "        \"function\": {\n",
    "            \"name\": \"generate_emoji\",\n",
    "            \"description\": \"根据提供的文本内容，生成一组适合小红书风格的表情符号。\",\n",
    "            \"parameters\": {\n",
    "                \"type\": \"object\",\n",
    "                \"properties\": {\n",
    "                    \"context\": {\n",
    "                        \"type\": \"string\",\n",
    "                        \"description\": \"文案的关键内容或情感，例如'惊喜效果'、'补水保湿'\"\n",
    "                    }\n",
    "                },\n",
    "                \"required\": [\"context\"]\n",
    "            }\n",
    "        }\n",
    "    }\n",
    "]"
   ],
   "id": "e1e3a04dc2d89ab",
   "outputs": [],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-19T13:50:04.445142Z",
     "start_time": "2025-08-19T13:50:04.436053Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import random   # 模拟生成表情\n",
    "import time     # 模拟网络请求延迟\n",
    "\n",
    "def mock_search_web(query: str) -> str:\n",
    "    \"\"\"模拟网络搜索函数工具，返回预设的搜索结果\"\"\"\n",
    "    print(f\"[Tool Call] 模拟搜索网页：{query}\")\n",
    "    time.sleep(1)  # 模拟网络延迟\n",
    "    if \"最新小红书美妆趋势\" in query:\n",
    "        return \"近期小红书美妆流行'多巴胺穿搭'、'早C晚A'护肤理念、'伪素颜'妆容，热门关键词有#氛围感、#抗老、#屏障修复。\"\n",
    "    elif \"保湿面膜\" in query:\n",
    "        return \"小红书保湿面膜热门话题：沙漠干皮救星、熬夜急救面膜、水光肌养成。用户痛点：卡粉、泛红、紧绷感。\"\n",
    "    elif \"深海蓝藻保湿面膜\" in query:\n",
    "        return \"关于深海蓝藻保湿面膜的用户评价：普遍反馈补水效果好，吸收快，对敏感肌友好。有用户提到价格略高，但效果值得。\"\n",
    "    else:\n",
    "        return f\"未找到关于 '{query}' 的特定信息，但市场反馈通常关注产品成分、功效和用户体验。\"\n",
    "\n",
    "def mock_query_product_database(product_name: str) -> str:\n",
    "    \"\"\"模拟查询产品数据库，返回预设的产品信息。\"\"\"\n",
    "    print(f\"[Tool Call] 模拟查询产品数据库：{product_name}\")\n",
    "    time.sleep(0.5) # 模拟数据库查询延迟\n",
    "    if \"深海蓝藻保湿面膜\" in product_name:\n",
    "        return \"深海蓝藻保湿面膜：核心成分为深海蓝藻提取物，富含多糖和氨基酸，能深层补水、修护肌肤屏障、舒缓敏感泛红。质地清爽不粘腻，适合所有肤质，尤其适合干燥、敏感肌。规格：25ml*5片。\"\n",
    "    elif \"美白精华\" in product_name:\n",
    "        return \"美白精华：核心成分是烟酰胺和VC衍生物，主要功效是提亮肤色、淡化痘印、改善暗沉。质地轻薄易吸收，适合需要均匀肤色的人群。\"\n",
    "    else:\n",
    "        return f\"产品数据库中未找到关于 '{product_name}' 的详细信息。\"\n",
    "\n",
    "def mock_generate_emoji(context: str) -> list:\n",
    "    \"\"\"模拟生成表情符号，根据上下文提供常用表情。\"\"\"\n",
    "    print(f\"[Tool Call] 模拟生成表情符号，上下文：{context}\")\n",
    "    time.sleep(0.2) # 模拟生成延迟\n",
    "    if \"补水\" in context or \"水润\" in context or \"保湿\" in context:\n",
    "        return [\"💦\", \"💧\", \"🌊\", \"✨\"]\n",
    "    elif \"惊喜\" in context or \"哇塞\" in context or \"爱了\" in context:\n",
    "        return [\"💖\", \"😍\", \"🤩\", \"💯\"]\n",
    "    elif \"熬夜\" in context or \"疲惫\" in context:\n",
    "        return [\"😭\", \"😮‍💨\", \"😴\", \"💡\"]\n",
    "    elif \"好物\" in context or \"推荐\" in context:\n",
    "        return [\"✅\", \"👍\", \"⭐\", \"🛍️\"]\n",
    "    else:\n",
    "        return random.sample([\"✨\", \"🔥\", \"💖\", \"💯\", \"🎉\", \"👍\", \"🤩\", \"💧\", \"🌿\"], k=min(5, len(context.split())))\n",
    "\n",
    "# 将模拟工具函数映射到一个字典，方便通过名称调用\n",
    "available_tools = {\n",
    "    \"search_web\": mock_search_web,\n",
    "    \"query_product_database\": mock_query_product_database,\n",
    "    \"generate_emoji\": mock_generate_emoji,\n",
    "}"
   ],
   "id": "1d36e1f6930af404",
   "outputs": [],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-19T13:50:08.603549Z",
     "start_time": "2025-08-19T13:50:08.591782Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import json\n",
    "import re\n",
    "\n",
    "def generate_rednote(product_name: str, tone_style: str=\"活泼甜美\", max_iterations: int=5) -> str:\n",
    "    \"\"\"\n",
    "    使用 DeepSeek Agent 生成小红书爆款文案。\n",
    "\n",
    "    Args:\n",
    "        product_name (str): 要生成文案的产品名称。\n",
    "        tone_style (str): 文案的语气和风格，如\"活泼甜美\"、\"知性\"、\"搞怪\"等。\n",
    "        max_iterations (int): Agent 最大迭代次数，防止无限循环。\n",
    "\n",
    "    Returns:\n",
    "        str: 生成的爆款文案（JSON 格式字符串）。\n",
    "    \"\"\"\n",
    "\n",
    "    print(f\"\\n🚀 启动小红书文案生成助手，产品：{product_name}，风格：{tone_style}\\n\")\n",
    "\n",
    "    messages = [\n",
    "        {\"role\": \"system\", \"content\": SYSTEM_PROMPT},\n",
    "        {\"role\": \"user\", \"content\": f\"请基于公司的产品信息、卖点、客户评价等，并结合网络最新热点，帮我为产品 [{product_name}] 生成一篇符合小红书爆款风格的笔记文案，语气风格为'{tone_style}',包含标题、正文、至少5个相关标签和5个表情符号。请严格遵循你的工作流程，以完整的 JSON 格式输出，并确保JSON内容使用markdown代码块包裹（例如：'''json{{...}}'''）\"}\n",
    "    ]\n",
    "\n",
    "    iteration_count = 0\n",
    "    final_response = None\n",
    "\n",
    "    while iteration_count < max_iterations:\n",
    "        iteration_count += 1\n",
    "        print(f\"--- 迭代轮次 {iteration_count} ---\")\n",
    "\n",
    "        try:\n",
    "            response = client.chat.completions.create(\n",
    "                # model=\"deepseek-chat\",\n",
    "                model=\"deepseek-r1:1.5b\",\n",
    "                messages=messages,\n",
    "                functions=TOOLS_DEFINITION,\n",
    "                function_call=\"auto\",  # 自动决定是否调用工具\n",
    "                temperature=0\n",
    "            )\n",
    "            response_message = response.choices[0].message\n",
    "\n",
    "            # ReAct 模式：处理工具调用\n",
    "            if response_message.tool_calls:     # 如果是由模型决定调用工具\n",
    "                print(\"Agent 决定调用工具...\")\n",
    "                messages.append(response_message)   # 将工具调用信息添加到对话历史\n",
    "\n",
    "                tool_outputs = []\n",
    "                for tool_call in response_message.tool_calls:\n",
    "                    # 确保参数是合法的json字符串，即使工具不要求参数，也要传递空字典\n",
    "                    function_name = tool_call.function.name\n",
    "                    function_args = json.loads(tool_call.function.arguments) if tool_call.function.arguments else {}\n",
    "\n",
    "                    print(f\"Agent Action: 调用工具 '{function_name}'，参数: {function_args}\")\n",
    "\n",
    "                    if function_name in available_tools:\n",
    "                        tool_function = available_tools[function_name]\n",
    "                        tool_result = tool_function(**function_args)\n",
    "                        print(f\"Observation：工具返回结果：{tool_result}\\n\")\n",
    "\n",
    "                        tool_outputs.append({\"tool_call_id\":tool_call.id,\n",
    "                                             \"role\":\"tool\",\n",
    "                                             \"content\":str(tool_result)})\n",
    "                    else:\n",
    "                        erroe_message = f\"错误：未找到名为 '{function_name}' 的工具。\"\n",
    "                        print(erroe_message)\n",
    "                        tool_outputs.append({\"tool_call_id\":tool_call.id,\n",
    "                                             \"role\":\"tool\",\n",
    "                                             \"content\":erroe_message})\n",
    "\n",
    "                messages.extend(tool_outputs)   # 将工具返回结果添加到对话历史\n",
    "\n",
    "            # ReAct 模式：处理最终内容\n",
    "            elif response_message.content:   # 如果模型直接给出回答（通常是最终答案）\n",
    "                print(f\"[模型生成结果] {response_message.content}\\n\")\n",
    "\n",
    "                json_string_match = re.search(r\"```json\\s*(\\{.*?\\})\\s*```\", response_message.content, re.DOTALL)\n",
    "\n",
    "                if json_string_match:\n",
    "                    extracted_json_content = json_string_match.group(1)\n",
    "\n",
    "                    try:\n",
    "                        final_response = json.loads(extracted_json_content)\n",
    "                        print(\"Agent：任务完成，成功解析最终JSON文案\")\n",
    "                        return json.dumps(final_response, ensure_ascii=False, indent=2)\n",
    "                    except json.JSONDecodeError as e:\n",
    "                        print(f\"Agent: 提取到JSON块但解析失败: {e}\")\n",
    "                        print(f\"尝试解析的字符串:\\n{extracted_json_content}\")\n",
    "                        messages.append(response_message) # 解析失败，继续对话\n",
    "                else:\n",
    "                    try:\n",
    "                        final_response = json.loads(response_message.content)\n",
    "                        print(\"Agent：任务完成，成功解析最终JSON文案\")\n",
    "                        return json.dumps(final_response, ensure_ascii=False, indent=2)\n",
    "                    except json.JSONDecodeError as e:\n",
    "                        print(\"Agent: 生成了非JSON格式内容或非Markdown JSON块，可能还在思考或出错。\")\n",
    "                        messages.append(response_message) # 非JSON格式，继续对话\n",
    "            else:\n",
    "                print(\"Agent：未知响应，可能是模型未能生成内容或工具调用。\")\n",
    "                break   # 结束循环\n",
    "        except Exception as e:\n",
    "            print(f\"调用 DeepSeek API 时发生错误: {e}\")\n",
    "            break\n",
    "\n",
    "    print(\"\\n⚠️ Agent 达到最大迭代次数或未能生成最终文案。请检查Prompt或增加迭代次数。\")\n",
    "    return \"未能成功生成文案。\""
   ],
   "id": "32d9d3096c2b1672",
   "outputs": [],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-15T07:48:17.974831Z",
     "start_time": "2025-08-15T07:47:49.180712Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 测试案例 1: 深海蓝藻保湿面膜\n",
    "product_name_1 = \"深海蓝藻保湿面膜\"\n",
    "tone_style_1 = \"活泼甜美\"\n",
    "result_1 = generate_rednote(product_name_1, tone_style_1)\n",
    "\n",
    "print(\"\\n--- 生成的文案 1 ---\")\n",
    "print(result_1)"
   ],
   "id": "230afdb4f5e674b7",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "🚀 启动小红书文案生成助手，产品：深海蓝藻保湿面膜，风格：活泼甜美\n",
      "\n",
      "--- 迭代轮次 1 ---\n",
      "[模型生成结果] ```json\n",
      "{\n",
      "  \"title\": \"💦深海蓝藻保湿面膜｜24小时水润不拔干！敏感肌也能用的补水神器✨\",\n",
      "  \"body\": \"姐妹们！发现了一款让我疯狂回购的面膜！就是这个【深海蓝藻保湿面膜！】\\n\\n🌟卖点1：采用1000米深海蓝藻提取物，补水能力是普通面膜的3倍！\\n🌟卖点2：0酒精0香精，本敏感肌用完完全不会泛红刺痛\\n🌟卖点3：膜布是日本进口天丝棉，薄到隐形还超级服帖\\n\\n最近换季皮肤干到爆皮，连续敷了3天，脸蛋就像喝饱了水一样Q弹！连我男票都夸皮肤在发光💡\\n\\n最惊喜的是！昨天带妆12小时居然一点都没卡粉！这持久保湿力我真的跪了🧎‍♀️\\n\\n现在买还送一盒旅行装！姐妹们快冲鸭！\\n\\n#保湿面膜推荐 #敏感肌必备 #换季护肤 #深海蓝藻 #平价好物\",\n",
      "  \"hashtags\": [\"#保湿面膜推荐\", \"#敏感肌必备\", \"#换季护肤\", \"#深海蓝藻\", \"#平价好物\"],\n",
      "  \"emojis\": [\"💦\", \"✨\", \"🌟\", \"💡\", \"🧎‍♀️\"]\n",
      "}\n",
      "```\n",
      "\n",
      "Agent：任务完成，成功解析最终JSON文案\n",
      "\n",
      "--- 生成的文案 1 ---\n",
      "{\n",
      "  \"title\": \"💦深海蓝藻保湿面膜｜24小时水润不拔干！敏感肌也能用的补水神器✨\",\n",
      "  \"body\": \"姐妹们！发现了一款让我疯狂回购的面膜！就是这个【深海蓝藻保湿面膜！】\\n\\n🌟卖点1：采用1000米深海蓝藻提取物，补水能力是普通面膜的3倍！\\n🌟卖点2：0酒精0香精，本敏感肌用完完全不会泛红刺痛\\n🌟卖点3：膜布是日本进口天丝棉，薄到隐形还超级服帖\\n\\n最近换季皮肤干到爆皮，连续敷了3天，脸蛋就像喝饱了水一样Q弹！连我男票都夸皮肤在发光💡\\n\\n最惊喜的是！昨天带妆12小时居然一点都没卡粉！这持久保湿力我真的跪了🧎‍♀️\\n\\n现在买还送一盒旅行装！姐妹们快冲鸭！\\n\\n#保湿面膜推荐 #敏感肌必备 #换季护肤 #深海蓝藻 #平价好物\",\n",
      "  \"hashtags\": [\n",
      "    \"#保湿面膜推荐\",\n",
      "    \"#敏感肌必备\",\n",
      "    \"#换季护肤\",\n",
      "    \"#深海蓝藻\",\n",
      "    \"#平价好物\"\n",
      "  ],\n",
      "  \"emojis\": [\n",
      "    \"💦\",\n",
      "    \"✨\",\n",
      "    \"🌟\",\n",
      "    \"💡\",\n",
      "    \"🧎‍♀️\"\n",
      "  ]\n",
      "}\n"
     ]
    }
   ],
   "execution_count": 39
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-15T06:01:13.424158Z",
     "start_time": "2025-08-15T06:01:06.599166Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 测试案例 2: 美白精华\n",
    "product_name_2 = \"美白精华\"\n",
    "tone_style_2 = \"知性温柔\"\n",
    "result_2 = generate_rednote(product_name_2, tone_style_2)\n",
    "\n",
    "print(\"\\n--- 生成的文案 2 ---\")\n",
    "print(result_2)"
   ],
   "id": "529b2b76cf11c2c6",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "🚀 启动小红书文案生成助手，产品：美白精华，风格：知性温柔\n",
      "\n",
      "--- 迭代轮次 1 ---\n",
      "[模型生成结果] ```json\n",
      "{\n",
      "  \"title\": \"✨28天逆袭冷白皮！这款美白精华让我素颜也发光✨\",\n",
      "  \"body\": \"最近被闺蜜疯狂追问的变白秘诀来啦～\\n\\n作为一个资深熬夜党+黄皮星人，这款美白精华真的让我惊艳到尖叫！💫\\n\\n🌟核心成分：\\n- 5%烟酰胺：温和提亮不刺激\\n- 传明酸+维C衍生物：双通路阻断黑色素\\n- 积雪草提取物：舒缓修护两不误\\n\\n🌸使用感受：\\n流动性超好的蛋清质地，上脸3秒就吸收！连续用两周就发现嘴角暗沉明显淡化，现在素颜涂个口红就能出门啦～\\n\\n💡小贴士：\\n建议晚上使用效果更佳哦～搭配防晒霜使用，白到反光不是梦！\\n\\n#美白精华 #黄皮逆袭 #护肤干货 #成分党 #冷白皮养成\",\n",
      "  \"hashtags\": [\"#美白精华\", \"#黄皮逆袭\", \"#护肤干货\", \"#成分党\", \"#冷白皮养成\"],\n",
      "  \"emojis\": [\"✨\", \"💫\", \"🌟\", \"🌸\", \"💡\"]\n",
      "}\n",
      "```\n",
      "\n",
      "Agent：任务完成，成功解析最终JSON文案\n",
      "\n",
      "--- 生成的文案 2 ---\n",
      "{\n",
      "  \"title\": \"✨28天逆袭冷白皮！这款美白精华让我素颜也发光✨\",\n",
      "  \"body\": \"最近被闺蜜疯狂追问的变白秘诀来啦～\\n\\n作为一个资深熬夜党+黄皮星人，这款美白精华真的让我惊艳到尖叫！💫\\n\\n🌟核心成分：\\n- 5%烟酰胺：温和提亮不刺激\\n- 传明酸+维C衍生物：双通路阻断黑色素\\n- 积雪草提取物：舒缓修护两不误\\n\\n🌸使用感受：\\n流动性超好的蛋清质地，上脸3秒就吸收！连续用两周就发现嘴角暗沉明显淡化，现在素颜涂个口红就能出门啦～\\n\\n💡小贴士：\\n建议晚上使用效果更佳哦～搭配防晒霜使用，白到反光不是梦！\\n\\n#美白精华 #黄皮逆袭 #护肤干货 #成分党 #冷白皮养成\",\n",
      "  \"hashtags\": [\n",
      "    \"#美白精华\",\n",
      "    \"#黄皮逆袭\",\n",
      "    \"#护肤干货\",\n",
      "    \"#成分党\",\n",
      "    \"#冷白皮养成\"\n",
      "  ],\n",
      "  \"emojis\": [\n",
      "    \"✨\",\n",
      "    \"💫\",\n",
      "    \"🌟\",\n",
      "    \"🌸\",\n",
      "    \"💡\"\n",
      "  ]\n",
      "}\n"
     ]
    }
   ],
   "execution_count": 10
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "7f4ba3a55a0b1377"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-19T14:38:03.412307Z",
     "start_time": "2025-08-19T14:38:03.403768Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import json\n",
    "\n",
    "def format_rednote_for_markdown(json_string: str) -> str:\n",
    "    \"\"\"\n",
    "    将 JSON 格式的小红书文案转换为 Markdown 格式，以便于阅读和发布。\n",
    "\n",
    "    Args:\n",
    "        json_string (str): 包含小红书文案的 JSON 字符串。\n",
    "                           预计格式为 {\"title\": \"...\", \"body\": \"...\", \"hashtags\": [...], \"emojis\": [...]}\n",
    "\n",
    "    Returns:\n",
    "        str: 格式化后的 Markdown 文本。\n",
    "    \"\"\"\n",
    "    try:\n",
    "        data = json.loads(json_string)\n",
    "    except json.JSONDecodeError as e:\n",
    "        return f\"错误：无法解析 JSON 字符串 - {e}\\n原始字符串：\\n{json_string}\"\n",
    "\n",
    "    title = data.get(\"title\", \"无标题\")\n",
    "    body = data.get(\"body\", \"\")\n",
    "    hashtags = data.get(\"hashtags\", [])\n",
    "    # 表情符号通常已经融入标题和正文中，这里可以选择是否单独列出\n",
    "    # emojis = data.get(\"emojis\", [])\n",
    "\n",
    "    # 构建 Markdown 文本\n",
    "    markdown_output = f\"## {title}\\n\\n\" # 标题使用二级标题\n",
    "\n",
    "    # 正文，保留换行符\n",
    "    markdown_output += f\"{body}\\n\\n\"\n",
    "\n",
    "    # Hashtags\n",
    "    if hashtags:\n",
    "        hashtag_string = \" \".join(hashtags) # 小红书标签通常是空格分隔\n",
    "        markdown_output += f\"{hashtag_string}\\n\"\n",
    "\n",
    "    # 如果需要，可以单独列出表情符号，但通常它们已经包含在标题和正文中\n",
    "    # if emojis:\n",
    "    #     emoji_string = \" \".join(emojis)\n",
    "    #     markdown_output += f\"\\n使用的表情：{emoji_string}\\n\"\n",
    "\n",
    "    return markdown_output.strip() # 去除末尾多余的空白"
   ],
   "id": "2fa2d710829aac51",
   "outputs": [],
   "execution_count": 8
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-15T07:54:44.418330Z",
     "start_time": "2025-08-15T07:54:44.413336Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# --- 示例使用 ---\n",
    "# 假设这是 generate_rednote 函数的输出\n",
    "generated_json_output = \"\"\"\n",
    "{\n",
    "  \"title\": \"✨ 28天逆袭冷白皮！这款美白精华让我告别暗沉痘印 🌟\",\n",
    "  \"body\": \"姐妹们！我终于找到了我的本命美白精华！💖\\\\n\\\\n作为一个常年熬夜➕痘印困扰的混油皮，肤色暗沉一直是我的心头大患。直到遇见了这款美白精华，简直打开了新世界的大门！🤩\\\\n\\\\n🌟 核心成分：烟酰胺+VC衍生物，双管齐下，提亮肤色效果绝绝子！\\\\n💧 质地轻薄到爆炸，上脸秒吸收，完全不会黏腻，油皮姐妹放心冲！\\\\n🌿 用了28天，痘印肉眼可见变淡了，整张脸都透亮了起来，素颜也能打！\\\\n\\\\n使用方法也很简单：早晚洁面后，滴2-3滴在手心，轻轻按压上脸，后续再叠加保湿产品就OK啦～\\\\n\\\\n真心推荐给所有想要均匀肤色、告别暗沉的姐妹！入股不亏！💖\",\n",
    "  \"hashtags\": [\"#美白精华\", \"#提亮肤色\", \"#淡化痘印\", \"#护肤好物\", \"#冷白皮\"],\n",
    "  \"emojis\": [\"✨\", \"💖\", \"🤩\", \"💧\", \"🌿\"]\n",
    "}\n",
    "\"\"\"\n",
    "\n",
    "# 调用格式化函数\n",
    "markdown_note = format_rednote_for_markdown(generated_json_output)\n",
    "\n",
    "# 打印结果\n",
    "print(\"--- 格式化后的小红书文案 (Markdown) ---\")\n",
    "print(markdown_note)\n",
    "\n",
    "# --- 另一个例子，假设JSON解析失败 ---\n",
    "invalid_json_output = \"{'title': 'Test', 'body': 'This is not valid json'}\" # 使用单引号，非法\n",
    "markdown_error_note = format_rednote_for_markdown(invalid_json_output)\n",
    "print(\"\\n--- 格式化错误示例 ---\")\n",
    "print(markdown_error_note)\n"
   ],
   "id": "9c4efd49855aa739",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--- 格式化后的小红书文案 (Markdown) ---\n",
      "## ✨ 28天逆袭冷白皮！这款美白精华让我告别暗沉痘印 🌟\n",
      "\n",
      "姐妹们！我终于找到了我的本命美白精华！💖\n",
      "\n",
      "作为一个常年熬夜➕痘印困扰的混油皮，肤色暗沉一直是我的心头大患。直到遇见了这款美白精华，简直打开了新世界的大门！🤩\n",
      "\n",
      "🌟 核心成分：烟酰胺+VC衍生物，双管齐下，提亮肤色效果绝绝子！\n",
      "💧 质地轻薄到爆炸，上脸秒吸收，完全不会黏腻，油皮姐妹放心冲！\n",
      "🌿 用了28天，痘印肉眼可见变淡了，整张脸都透亮了起来，素颜也能打！\n",
      "\n",
      "使用方法也很简单：早晚洁面后，滴2-3滴在手心，轻轻按压上脸，后续再叠加保湿产品就OK啦～\n",
      "\n",
      "真心推荐给所有想要均匀肤色、告别暗沉的姐妹！入股不亏！💖\n",
      "\n",
      "#美白精华 #提亮肤色 #淡化痘印 #护肤好物 #冷白皮\n",
      "\n",
      "--- 格式化错误示例 ---\n",
      "错误：无法解析 JSON 字符串 - Expecting property name enclosed in double quotes: line 1 column 2 (char 1)\n",
      "原始字符串：\n",
      "{'title': 'Test', 'body': 'This is not valid json'}\n"
     ]
    }
   ],
   "execution_count": 41
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-15T07:55:18.288987Z",
     "start_time": "2025-08-15T07:55:18.284748Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 调用格式化函数\n",
    "markdown_note = format_rednote_for_markdown(result_1)\n",
    "\n",
    "# 打印结果\n",
    "print(\"--- 格式化后的小红书文案 (Markdown) ---\")\n",
    "print(markdown_note)"
   ],
   "id": "9ac16cffe1d44a8d",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--- 格式化后的小红书文案 (Markdown) ---\n",
      "## 💦深海蓝藻保湿面膜｜24小时水润不拔干！敏感肌也能用的补水神器✨\n",
      "\n",
      "姐妹们！发现了一款让我疯狂回购的面膜！就是这个【深海蓝藻保湿面膜！】\n",
      "\n",
      "🌟卖点1：采用1000米深海蓝藻提取物，补水能力是普通面膜的3倍！\n",
      "🌟卖点2：0酒精0香精，本敏感肌用完完全不会泛红刺痛\n",
      "🌟卖点3：膜布是日本进口天丝棉，薄到隐形还超级服帖\n",
      "\n",
      "最近换季皮肤干到爆皮，连续敷了3天，脸蛋就像喝饱了水一样Q弹！连我男票都夸皮肤在发光💡\n",
      "\n",
      "最惊喜的是！昨天带妆12小时居然一点都没卡粉！这持久保湿力我真的跪了🧎‍♀️\n",
      "\n",
      "现在买还送一盒旅行装！姐妹们快冲鸭！\n",
      "\n",
      "#保湿面膜推荐 #敏感肌必备 #换季护肤 #深海蓝藻 #平价好物\n",
      "\n",
      "#保湿面膜推荐 #敏感肌必备 #换季护肤 #深海蓝藻 #平价好物\n"
     ]
    }
   ],
   "execution_count": 42
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "d4578211745df3ad"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "460bfc68e379a479"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 扩展练习",
   "id": "40952f515323832e"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-15T08:27:30.211158Z",
     "start_time": "2025-08-15T08:27:15.814520Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 测试案例 3: 手持小风扇\n",
    "product_name_3 = \"手持小风扇\"\n",
    "tone_style_3 = \"甜美可爱\"\n",
    "result_3 = generate_rednote(product_name_3, tone_style_3)\n",
    "\n",
    "print(\"\\n--- 生成的文案 3 ---\")\n",
    "print(result_3)"
   ],
   "id": "49900be01acd2fa9",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "🚀 启动小红书文案生成助手，产品：手持小风扇，风格：甜美可爱\n",
      "\n",
      "--- 迭代轮次 1 ---\n",
      "[模型生成结果] ```json\n",
      "{\n",
      "  \"title\": \"💕夏日续命神器！这款手持小风扇也太可爱了吧～\",\n",
      "  \"body\": \"姐妹们！发现了一个夏日必备的宝藏小风扇✨\\n\\n🌬️三档风力调节，静音又强劲！出门逛街再也不怕花妆啦～\\n\\n🌈马卡龙色系超治愈，拿在手里就是最靓的崽！\\n\\n🔋充一次电能用8小时！放包里完全不占地方\\n\\n💯被闺蜜追着问链接！都说这是今夏最值得入手的小物件\\n\\nPS：最近超火的露营带着它真的绝配！拍照也超上镜der～\",\n",
      "  \"hashtags\": [\"#夏日好物\", \"#手持小风扇\", \"#少女心好物\", \"#降温神器\", \"#好物分享\"],\n",
      "  \"emojis\": [\"🌬️\", \"🌈\", \"💕\", \"✨\", \"💯\"]\n",
      "}\n",
      "```\n",
      "\n",
      "Agent：任务完成，成功解析最终JSON文案\n",
      "\n",
      "--- 生成的文案 3 ---\n",
      "{\n",
      "  \"title\": \"💕夏日续命神器！这款手持小风扇也太可爱了吧～\",\n",
      "  \"body\": \"姐妹们！发现了一个夏日必备的宝藏小风扇✨\\n\\n🌬️三档风力调节，静音又强劲！出门逛街再也不怕花妆啦～\\n\\n🌈马卡龙色系超治愈，拿在手里就是最靓的崽！\\n\\n🔋充一次电能用8小时！放包里完全不占地方\\n\\n💯被闺蜜追着问链接！都说这是今夏最值得入手的小物件\\n\\nPS：最近超火的露营带着它真的绝配！拍照也超上镜der～\",\n",
      "  \"hashtags\": [\n",
      "    \"#夏日好物\",\n",
      "    \"#手持小风扇\",\n",
      "    \"#少女心好物\",\n",
      "    \"#降温神器\",\n",
      "    \"#好物分享\"\n",
      "  ],\n",
      "  \"emojis\": [\n",
      "    \"🌬️\",\n",
      "    \"🌈\",\n",
      "    \"💕\",\n",
      "    \"✨\",\n",
      "    \"💯\"\n",
      "  ]\n",
      "}\n"
     ]
    }
   ],
   "execution_count": 43
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-15T08:29:06.621312Z",
     "start_time": "2025-08-15T08:28:57.652919Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 测试案例 4: 彩贝小风铃\n",
    "product_name_4 = \"彩贝小风铃\"\n",
    "tone_style_4 = \"清新自然\"\n",
    "result_4 = generate_rednote(product_name_4, tone_style_4)\n",
    "\n",
    "print(\"\\n--- 生成的文案 4 ---\")\n",
    "print(result_4)"
   ],
   "id": "467e239151917d8e",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "🚀 启动小红书文案生成助手，产品：彩贝小风铃，风格：清新自然\n",
      "\n",
      "--- 迭代轮次 1 ---\n",
      "[模型生成结果] ```json\n",
      "{\n",
      "  \"title\": \"✨叮咚～我的窗台住进了一串会唱歌的贝壳！彩贝小风铃治愈系开箱💫\",\n",
      "  \"body\": \"最近被小红书种草了这个【彩贝小风铃】🌊\\n\\n一打开包装就被惊艳到！每一片贝壳都是天然色泽🌈 阳光底下会折射出细碎的光斑，像把整个海边的温柔都挂在了窗前～\\n\\n🍃最绝的是风来的声音！不是普通金属铃的刺耳响，是那种「叮铃——叮铃——」的空灵感，工作室小伙伴都说像人鱼在唱歌🧜♀️\\n\\n▫️天然贝壳+手工打磨（边缘圆润不割手）\\n▫️赠送可调节麻绳（阳台/书房/婴儿房都能挂）\\n▫️礼盒包装自带薰衣草香包（送闺蜜被夸爆！）\\n\\n刚挂上就引来邻居阿姨问链接🤣 最近《我的阿勒泰》同款治愈风好火，这个自带文艺滤镜的小风铃简直氛围感神器！听风看云发呆，瞬间治愈打工人的精神内耗🌿\\n\\nP.S. 下雨天声音更空灵哦～已经安利给全办公室啦！\",\n",
      "  \"hashtags\": [\"#治愈系好物\", \"#手工风铃\", \"#居家好物\", \"#提升幸福感的小物件\", \"#我的阿勒泰同款\"],\n",
      "  \"emojis\": [\"🌊\", \"🌈\", \"🧜♀️\", \"🌿\", \"💫\"]\n",
      "}\n",
      "```\n",
      "\n",
      "Agent：任务完成，成功解析最终JSON文案\n",
      "\n",
      "--- 生成的文案 4 ---\n",
      "{\n",
      "  \"title\": \"✨叮咚～我的窗台住进了一串会唱歌的贝壳！彩贝小风铃治愈系开箱💫\",\n",
      "  \"body\": \"最近被小红书种草了这个【彩贝小风铃】🌊\\n\\n一打开包装就被惊艳到！每一片贝壳都是天然色泽🌈 阳光底下会折射出细碎的光斑，像把整个海边的温柔都挂在了窗前～\\n\\n🍃最绝的是风来的声音！不是普通金属铃的刺耳响，是那种「叮铃——叮铃——」的空灵感，工作室小伙伴都说像人鱼在唱歌🧜♀️\\n\\n▫️天然贝壳+手工打磨（边缘圆润不割手）\\n▫️赠送可调节麻绳（阳台/书房/婴儿房都能挂）\\n▫️礼盒包装自带薰衣草香包（送闺蜜被夸爆！）\\n\\n刚挂上就引来邻居阿姨问链接🤣 最近《我的阿勒泰》同款治愈风好火，这个自带文艺滤镜的小风铃简直氛围感神器！听风看云发呆，瞬间治愈打工人的精神内耗🌿\\n\\nP.S. 下雨天声音更空灵哦～已经安利给全办公室啦！\",\n",
      "  \"hashtags\": [\n",
      "    \"#治愈系好物\",\n",
      "    \"#手工风铃\",\n",
      "    \"#居家好物\",\n",
      "    \"#提升幸福感的小物件\",\n",
      "    \"#我的阿勒泰同款\"\n",
      "  ],\n",
      "  \"emojis\": [\n",
      "    \"🌊\",\n",
      "    \"🌈\",\n",
      "    \"🧜♀️\",\n",
      "    \"🌿\",\n",
      "    \"💫\"\n",
      "  ]\n",
      "}\n"
     ]
    }
   ],
   "execution_count": 44
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-15T08:32:02.569914Z",
     "start_time": "2025-08-15T08:31:56.610092Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 测试案例 5: 拉布布手工娃娃\n",
    "product_name_5 = \"拉布布手工娃娃\"\n",
    "tone_style_5 = \"优雅大方\"\n",
    "result_5 = generate_rednote(product_name_5, tone_style_5)\n",
    "\n",
    "print(\"\\n--- 生成的文案 5 ---\")\n",
    "print(result_5)"
   ],
   "id": "6f727100da8398a1",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "🚀 启动小红书文案生成助手，产品：拉布布手工娃娃，风格：优雅大方\n",
      "\n",
      "--- 迭代轮次 1 ---\n",
      "[模型生成结果] ```json\n",
      "{\n",
      "  \"title\": \"✨治愈系拉布布手工娃娃｜每个细节都是匠心的温度💖\",\n",
      "  \"body\": \"最近被这款拉布布手工娃娃彻底治愈了！\\n\\n🌟 纯手工缝制，每一针每一线都倾注了匠人的心血，触感柔软到让人忍不住一直抱在怀里～\\n\\n🎀 采用顶级棉麻面料，安全无刺激，连小宝宝都可以放心玩耍！\\n\\n💫 最打动我的是它呆萌的表情和独特的造型设计，放在房间里瞬间提升温馨感，拍照更是ins风满满～\\n\\n🔥 据说是小红书最近超火的治愈系」单品，好多博主都在晒！\\n\\n💌 已经入手了三个不同造型的，每天根据心情换着抱，幸福感爆棚！\\n\\n#手工娃娃 #治愈系好物 #拉布布 #家居好物 #ins风家居\",\n",
      "  \"hashtags\": [\"#手工娃娃\", \"#治愈系好物\", \"#拉布布\", \"#家居好物\", \"#ins风家居\"],\n",
      "  \"emojis\": [\"✨\", \"💖\", \"🌟\", \"🎀\", \"💫\"]\n",
      "}\n",
      "```\n",
      "\n",
      "Agent：任务完成，成功解析最终JSON文案\n",
      "\n",
      "--- 生成的文案 5 ---\n",
      "{\n",
      "  \"title\": \"✨治愈系拉布布手工娃娃｜每个细节都是匠心的温度💖\",\n",
      "  \"body\": \"最近被这款拉布布手工娃娃彻底治愈了！\\n\\n🌟 纯手工缝制，每一针每一线都倾注了匠人的心血，触感柔软到让人忍不住一直抱在怀里～\\n\\n🎀 采用顶级棉麻面料，安全无刺激，连小宝宝都可以放心玩耍！\\n\\n💫 最打动我的是它呆萌的表情和独特的造型设计，放在房间里瞬间提升温馨感，拍照更是ins风满满～\\n\\n🔥 据说是小红书最近超火的治愈系」单品，好多博主都在晒！\\n\\n💌 已经入手了三个不同造型的，每天根据心情换着抱，幸福感爆棚！\\n\\n#手工娃娃 #治愈系好物 #拉布布 #家居好物 #ins风家居\",\n",
      "  \"hashtags\": [\n",
      "    \"#手工娃娃\",\n",
      "    \"#治愈系好物\",\n",
      "    \"#拉布布\",\n",
      "    \"#家居好物\",\n",
      "    \"#ins风家居\"\n",
      "  ],\n",
      "  \"emojis\": [\n",
      "    \"✨\",\n",
      "    \"💖\",\n",
      "    \"🌟\",\n",
      "    \"🎀\",\n",
      "    \"💫\"\n",
      "  ]\n",
      "}\n"
     ]
    }
   ],
   "execution_count": 45
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-15T08:32:49.157532Z",
     "start_time": "2025-08-15T08:32:49.153738Z"
    }
   },
   "cell_type": "code",
   "source": [
    "markdown_note = format_rednote_for_markdown(result_5)\n",
    "print(markdown_note)"
   ],
   "id": "89f6ce74a275b127",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "## ✨治愈系拉布布手工娃娃｜每个细节都是匠心的温度💖\n",
      "\n",
      "最近被这款拉布布手工娃娃彻底治愈了！\n",
      "\n",
      "🌟 纯手工缝制，每一针每一线都倾注了匠人的心血，触感柔软到让人忍不住一直抱在怀里～\n",
      "\n",
      "🎀 采用顶级棉麻面料，安全无刺激，连小宝宝都可以放心玩耍！\n",
      "\n",
      "💫 最打动我的是它呆萌的表情和独特的造型设计，放在房间里瞬间提升温馨感，拍照更是ins风满满～\n",
      "\n",
      "🔥 据说是小红书最近超火的治愈系」单品，好多博主都在晒！\n",
      "\n",
      "💌 已经入手了三个不同造型的，每天根据心情换着抱，幸福感爆棚！\n",
      "\n",
      "#手工娃娃 #治愈系好物 #拉布布 #家居好物 #ins风家居\n",
      "\n",
      "#手工娃娃 #治愈系好物 #拉布布 #家居好物 #ins风家居\n"
     ]
    }
   ],
   "execution_count": 46
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "1e76466a6be0dcd3"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 第六章作业",
   "id": "f79bf26712a0bc77"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-19T14:39:58.231032Z",
     "start_time": "2025-08-19T14:38:09.698575Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 测试案例 5: 拉布布手工娃娃\n",
    "product_name_5 = \"蓝牙降噪耳机\"\n",
    "tone_style_5 = \"优雅大方\"\n",
    "result_5 = generate_rednote(product_name_5, tone_style_5)\n",
    "\n",
    "print(\"\\n--- 生成的文案 5 ---\")\n",
    "print(result_5)\n",
    "\n",
    "markdown_note = format_rednote_for_markdown(result_5)\n",
    "print(markdown_note)"
   ],
   "id": "7b7da95d51cab92c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "🚀 启动小红书文案生成助手，产品：蓝牙降噪耳机，风格：优雅大方\n",
      "\n",
      "--- 迭代轮次 1 ---\n",
      "[模型生成结果] <think>\n",
      "好，我现在需要帮用户生成一篇关于蓝牙降噪耳机的小红书爆款笔记文案。首先，我得仔细分析用户的需求和提供的信息。\n",
      "\n",
      "用户提到要结合最新潮流和产品卖点，同时要有吸引力的语气风格，特别是“优雅大方”。这意味着文案不仅要实用，还要显得时尚且有高级感。接下来，我需要收集相关的产品信息、客户评价以及热点信息。\n",
      "\n",
      "首先，我应该查看公司的蓝牙降噪耳机产品信息，包括型号、功能、适用场景等。然后，看看有没有客户评价或者用户反馈，这些可以增加产品的可信度和吸引力。同时，结合最近的网络热点，比如科技、时尚、潮流相关的话题，来丰富文案的内容。\n",
      "\n",
      "接下来，我会考虑如何将这些信息整合成一篇吸引人的小红书笔记。标题要简洁有力，突出产品的优势和独特卖点。正文部分需要详细描述产品的功能、适用人群以及搭配建议，同时加入一些时尚元素，比如配饰或搭配方式，让整体看起来更高级。\n",
      "\n",
      "关于标签，我需要选择那些能准确反映产品特点的词汇，比如“降噪蓝牙”、“降噪耳机”、“科技感”、“舒适度”等。这些标签能够帮助用户快速找到相关的产品信息，并且增加文案的曝光率。\n",
      "\n",
      "表情符号方面，考虑到产品的优雅大方风格，可以选择一些适合搭配的emoji，比如✨、🔥、💖等，来增强文案的感染力和视觉效果。\n",
      "\n",
      "最后，我会按照工作流程，先思考收集信息，然后生成文案，确保每个部分都符合用户的要求，并且语气要优雅大方。同时，使用JSON格式输出，确保结构正确，内容完整。\n",
      "</think>\n",
      "\n",
      "```json\n",
      "{\n",
      "  \"title\": \"蓝牙降噪耳机 满足日常需求的高级科技产品\",\n",
      "  \"body\": \"今天给大家推荐一款非常实用的蓝牙降噪耳机，它不仅能够有效隔绝噪音，还能带来极佳的舒适感。这款耳机采用高端材质，搭配先进的降噪算法，让你在任何场合都能保持专注。无论是工作、学习还是休闲，这款耳机都能让你的听觉体验更加清晰。如果你正在寻找一款既实用又时尚的蓝牙耳机，那么这款款款绝对是一个不错的选择。它不仅适合日常使用，还能为你的生活增添一份高级感。搭配一些精致的配饰，比如耳塞套或头带，让你的耳机在任何场合都能完美paired。无论是朋友聚会还是家庭聚会，这款耳机都能让你的交流更加顺畅。如果你正在寻找一款既实用又时尚的蓝牙耳机，那么这款款款绝对是一个不错的选择。它不仅适合日常使用，还能为你的生活增添一份高级感。搭配一些精致的配饰，比如耳塞套或头带，让你的耳机在任何场合都能完美paired。无论是朋友聚会还是家庭聚会，这款耳机都能让你的交流更加顺畅。\",\n",
      "  \"hashtags\": [\"#降噪蓝牙耳机\", \"#科技降噪耳机\", \"#舒适蓝牙耳机\", \"#高级蓝牙耳机\", \"#时尚蓝牙耳机\"],\n",
      "  \"emojis\": [\"✨\", \"🔥\", \"💖\"]\n",
      "}\n",
      "```\n",
      "\n",
      "Agent：任务完成，成功解析最终JSON文案\n",
      "\n",
      "--- 生成的文案 5 ---\n",
      "{\n",
      "  \"title\": \"蓝牙降噪耳机 满足日常需求的高级科技产品\",\n",
      "  \"body\": \"今天给大家推荐一款非常实用的蓝牙降噪耳机，它不仅能够有效隔绝噪音，还能带来极佳的舒适感。这款耳机采用高端材质，搭配先进的降噪算法，让你在任何场合都能保持专注。无论是工作、学习还是休闲，这款耳机都能让你的听觉体验更加清晰。如果你正在寻找一款既实用又时尚的蓝牙耳机，那么这款款款绝对是一个不错的选择。它不仅适合日常使用，还能为你的生活增添一份高级感。搭配一些精致的配饰，比如耳塞套或头带，让你的耳机在任何场合都能完美paired。无论是朋友聚会还是家庭聚会，这款耳机都能让你的交流更加顺畅。如果你正在寻找一款既实用又时尚的蓝牙耳机，那么这款款款绝对是一个不错的选择。它不仅适合日常使用，还能为你的生活增添一份高级感。搭配一些精致的配饰，比如耳塞套或头带，让你的耳机在任何场合都能完美paired。无论是朋友聚会还是家庭聚会，这款耳机都能让你的交流更加顺畅。\",\n",
      "  \"hashtags\": [\n",
      "    \"#降噪蓝牙耳机\",\n",
      "    \"#科技降噪耳机\",\n",
      "    \"#舒适蓝牙耳机\",\n",
      "    \"#高级蓝牙耳机\",\n",
      "    \"#时尚蓝牙耳机\"\n",
      "  ],\n",
      "  \"emojis\": [\n",
      "    \"✨\",\n",
      "    \"🔥\",\n",
      "    \"💖\"\n",
      "  ]\n",
      "}\n",
      "## 蓝牙降噪耳机 满足日常需求的高级科技产品\n",
      "\n",
      "今天给大家推荐一款非常实用的蓝牙降噪耳机，它不仅能够有效隔绝噪音，还能带来极佳的舒适感。这款耳机采用高端材质，搭配先进的降噪算法，让你在任何场合都能保持专注。无论是工作、学习还是休闲，这款耳机都能让你的听觉体验更加清晰。如果你正在寻找一款既实用又时尚的蓝牙耳机，那么这款款款绝对是一个不错的选择。它不仅适合日常使用，还能为你的生活增添一份高级感。搭配一些精致的配饰，比如耳塞套或头带，让你的耳机在任何场合都能完美paired。无论是朋友聚会还是家庭聚会，这款耳机都能让你的交流更加顺畅。如果你正在寻找一款既实用又时尚的蓝牙耳机，那么这款款款绝对是一个不错的选择。它不仅适合日常使用，还能为你的生活增添一份高级感。搭配一些精致的配饰，比如耳塞套或头带，让你的耳机在任何场合都能完美paired。无论是朋友聚会还是家庭聚会，这款耳机都能让你的交流更加顺畅。\n",
      "\n",
      "#降噪蓝牙耳机 #科技降噪耳机 #舒适蓝牙耳机 #高级蓝牙耳机 #时尚蓝牙耳机\n"
     ]
    }
   ],
   "execution_count": 9
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "368192b51957a97f"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
